 
// <Template>
//   <SolutionTemplate></SolutionTemplate>
//   <Version>20110104.1</Version>
//   <Update></Update>
// </Template>

// <Template>
//   <SolutionTemplate></SolutionTemplate>
//   <Version>20110316.1</Version>
//   <Update></Update>
// </Template>

// <Template>
//   <SolutionTemplate></SolutionTemplate>
//   <Version>20110122.1</Version>
//   <Update></Update>
// </Template>
 
// <Template>
//   <SolutionTemplate></SolutionTemplate>
//   <Version>20110124.1</Version>
//   <Update></Update>
// </Template>

// <Template>
//   <SolutionTemplate></SolutionTemplate>
//   <Version>20110113.1</Version>
//   <Update></Update>
// </Template>




// <Template>
//   <SolutionTemplate></SolutionTemplate>
//   <Version>20110317.1</Version>
//   <Update></Update>
// </Template>


// <Template>
//   <SolutionTemplate></SolutionTemplate>
//   <Version>20110117.1</Version>
//   <Update></Update>
// </Template>



// <Template>
//   <SolutionTemplate></SolutionTemplate>
//   <Version>20101221.1</Version>
//   <Update></Update>
// </Template>





// <Template>
//   <SolutionTemplate></SolutionTemplate>
//   <Version>20110316.1</Version>
//   <Update></Update>
// </Template>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using SFS.SampleApp.Web.Mvc.Resources;
using System.Runtime.Serialization;
using SFSdotNet.Framework.Web.Mvc.Models;
using SFSdotNet.Framework.Web.Mvc.Extensions;
using BO = SFS.SampleApp.BusinessObjects;
using System.Web.Mvc;
using SFSdotNet.Framework.Web.Mvc.Validation;
using SFSdotNet.Framework.Web.Mvc.Models;
using SFSdotNet.Framework.Web.Mvc.Resources;
using SFSdotNet.Framework.Entities.Metadata;


namespace SFS.SampleApp.Web.Mvc.Models.Addresses 
{
	public partial class AddressModel: ModelBase{
		public AddressModel()
        {
		}
		public override string Id
        {
            get
            {
                return this.AddressID.ToString();
            }
        }
			
			
        public override string ToString()
        {
		
            return this.AddressLine1.ToString();
		
        }    
			
	
		[SystemProperty()]		
		public Int32? AddressID{ get; set; }
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_ADDRESSLINE1_REQUIRED", ErrorMessageResourceType=typeof(AddressResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("ADDRESSLINE1", NameResourceType=typeof(AddressResources))]
	public String   AddressLine1 { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[LocalizedDisplayName("ADDRESSLINE2", NameResourceType=typeof(AddressResources))]
	public String   AddressLine2 { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_CITY_REQUIRED", ErrorMessageResourceType=typeof(AddressResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("CITY", NameResourceType=typeof(AddressResources))]
	public String   City { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_STATEPROVINCE_REQUIRED", ErrorMessageResourceType=typeof(AddressResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("STATEPROVINCE", NameResourceType=typeof(AddressResources))]
	public String   StateProvince { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_COUNTRYREGION_REQUIRED", ErrorMessageResourceType=typeof(AddressResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("COUNTRYREGION", NameResourceType=typeof(AddressResources))]
	public String   CountryRegion { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_POSTALCODE_REQUIRED", ErrorMessageResourceType=typeof(AddressResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("POSTALCODE", NameResourceType=typeof(AddressResources))]
	public String   PostalCode { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[SystemProperty()]
	[LocalizedDisplayName("ROWGUID", NameResourceType=typeof(AddressResources))]
	public Guid   rowguid { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_MODIFIEDDATE_REQUIRED", ErrorMessageResourceType=typeof(AddressResources))]
		
	[RelationFilterable()]
	[DateTime(true, false, null)]	
	[LocalizedDisplayName("MODIFIEDDATE", NameResourceType=typeof(AddressResources))]
	public DateTime   ModifiedDate { get; set; }
	public string ModifiedDateText {
        get {
            if (ModifiedDate != null)
			
                return ((DateTime)ModifiedDate).ToShortDateString();
            else
                return String.Empty;
        }
				set{
				this.ModifiedDate = Convert.ToDateTime(value);
    }
		}
		
		
		
		[LocalizedDisplayName("CUSTOMERADDRESSES", NameResourceType=typeof(AddressResources))]
		[RelationFilterable(IsNavigationPropertyMany=true, FiltrablePropertyPathName="CustomerAddresses.Count()", ModelPartialType="CustomerAddresses.CustomerAddress")]
        public List<CustomerAddresses.CustomerAddressModel> CustomerAddresses { get; set; }			
	
		[LocalizedDisplayName("SALESORDERHEADERS", NameResourceType=typeof(AddressResources))]
		[RelationFilterable(IsNavigationPropertyMany=true, FiltrablePropertyPathName="SalesOrderHeaders.Count()", ModelPartialType="SalesOrderHeaders.SalesOrderHeader")]
        public List<SalesOrderHeaders.SalesOrderHeaderModel> SalesOrderHeaders { get; set; }			
	
		[LocalizedDisplayName("SALESORDERHEADERS1", NameResourceType=typeof(AddressResources))]
		[RelationFilterable(IsNavigationPropertyMany=true, FiltrablePropertyPathName="SalesOrderHeaders1.Count()", ModelPartialType="SalesOrderHeaders.SalesOrderHeader")]
        public List<SalesOrderHeaders.SalesOrderHeaderModel> SalesOrderHeaders1 { get; set; }			
	
	public override string SafeKey
   	{
		get
        {
			if(this.AddressID != null)
				return SFSdotNet.Framework.Entities.Utils.GetKey(this ,"AddressID").Replace("/","-");
			else
				return String.Empty;
		}
    }		
		public void Bind(AddressModel model){
            
		this.AddressID = model.AddressID;
		this.AddressLine1 = model.AddressLine1;
		this.AddressLine2 = model.AddressLine2;
		this.City = model.City;
		this.StateProvince = model.StateProvince;
		this.CountryRegion = model.CountryRegion;
		this.PostalCode = model.PostalCode;
		this.rowguid = model.rowguid;
		this.ModifiedDate = model.ModifiedDate;
        }

        public BusinessObjects.Address GetBusinessObject()
        {
            BusinessObjects.Address result = new BusinessObjects.Address();
	if (this.AddressID != null )
				result.AddressID = (Int32)this.AddressID;
				
	if (this.AddressLine1 != null )
				result.AddressLine1 = (String)this.AddressLine1.Trim().Replace("\t", String.Empty);
				
	if (this.AddressLine2 != null )
				result.AddressLine2 = (String)this.AddressLine2.Trim().Replace("\t", String.Empty);
				
	if (this.City != null )
				result.City = (String)this.City.Trim().Replace("\t", String.Empty);
				
	if (this.StateProvince != null )
				result.StateProvince = (String)this.StateProvince.Trim().Replace("\t", String.Empty);
				
	if (this.CountryRegion != null )
				result.CountryRegion = (String)this.CountryRegion.Trim().Replace("\t", String.Empty);
				
	if (this.PostalCode != null )
				result.PostalCode = (String)this.PostalCode.Trim().Replace("\t", String.Empty);
				
	if (this.rowguid != null )
				result.rowguid = (Guid)this.rowguid;
				
				result.ModifiedDate = (DateTime)this.ModifiedDate;		
				



            return result;
        }
        public void Bind(BusinessObjects.Address businessObject)
        {
            
			this.AddressID = businessObject.AddressID;
				
			this.AddressLine1 = businessObject.AddressLine1 != null ? businessObject.AddressLine1.Trim().Replace("\t", String.Empty) : "";
				
				
	if (businessObject.AddressLine2 != null )
				this.AddressLine2 = (String)businessObject.AddressLine2;
			this.City = businessObject.City != null ? businessObject.City.Trim().Replace("\t", String.Empty) : "";
				
			this.StateProvince = businessObject.StateProvince != null ? businessObject.StateProvince.Trim().Replace("\t", String.Empty) : "";
				
			this.CountryRegion = businessObject.CountryRegion != null ? businessObject.CountryRegion.Trim().Replace("\t", String.Empty) : "";
				
			this.PostalCode = businessObject.PostalCode != null ? businessObject.PostalCode.Trim().Replace("\t", String.Empty) : "";
				
			this.rowguid = businessObject.rowguid;
				
				this.ModifiedDate = (DateTime)businessObject.ModifiedDate;
           
        }
	}
}
